home *** CD-ROM | disk | FTP | other *** search
- Path: cs.tu-berlin.de!news
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.lang.c++
- Subject: Re: problem with bc++ (2) answers please
- Date: 29 Feb 1996 22:04:53 GMT
- Organization: Technical University of Berlin, Germany
- Message-ID: <4h57u5$57d@news.cs.tu-berlin.de>
- NNTP-Posting-Host: 130.149.17.223
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
-
- aragonne@mail.planete.net (ragonnet alain) writes:
- > /*********************************************************************
- > * PROGAMME AVEC BC++ VERSION 4.52
- > *********************************************************************/
- >
- > #include<stdio.h>
- >
- > main( void)
- > {
- > int tab[]= { 0, 1, 2}, *ptr= tab;
- >
- > printf("\n ref: %d , pointeur: %d\n", ptr, *ptr);
- > /*instruction qui ne fonctionne pas avec BC++ */ (this instrucion is not ok with BC++)
- > printf("\n ref: %d", ptr);
- > printf("\n pointeur: %d", *ptr);
- > /*Ces 2 instructions fonctionnent correctement */(this two instructions are ok )
- > }
- > /*
- >
- > ref: 3672 , pointeur: 0
- >
- > ref: 3672
- > pointeur: 0
- > Peut-on me dire d'ou vient le probleme.Ce programme fonctionne
- > correctement avec QC 2.5 par exemple*/
- >
- > Can you tell me where is the problem please.This program is working well
- > with QC 2.5 for exemple*/
- >
- > thank you for answers
- >
-
- The problem is the pointer size. Generally you can't printf a pointer value
- with the "%d" format since in this case an integer is expected which is
- ( on MSDOS machines ) 2 bytes long. The size of a pointer, on the contrary,
- depends on the memory model. If you use the SMALL model everything is fine
- since a pointer is 2 bytes then. In the LARGE model, however, the pointer
- is 4 bytes. Thus, is you call printf( "%d %d", ptr, *ptr ) the first "%d"
- prints the lower two bytes of the pointer and the second the higher ones.
- Just correct the first "%d" to "%lp" and it should work fine.
-
- Bye
-
- Roman
-
-